﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace Tech4WPF_TestApp
{
    /// <summary>
    /// Interaction logic for GaugeControlTest.xaml
    /// </summary>
    public partial class GaugeControlTest : Window
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="GaugeControlTest"/> class.
        /// </summary>
        public GaugeControlTest()
        {
            InitializeComponent();
        }

        #endregion Constructors

        #region Properties

        System.Windows.Forms.ColorDialog colorPicker;
        /// <summary>
        /// Gets the color picker. (singleton)
        /// </summary>
        private System.Windows.Forms.ColorDialog ColorPicker
        {
            get
            {
                if (this.colorPicker == null)
                {
                    this.colorPicker = new System.Windows.Forms.ColorDialog();
                }
                return this.colorPicker;
            }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Handles the MouseMove event of the rectangle control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
        private void rectangle_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePosition = e.GetPosition(this.rectangle);
            mousePosition.Y = Math.Abs(mousePosition.Y - this.rectangle.ActualHeight);

            this.gaugeControlX.Value = gaugeControlX.Minimum + (mousePosition.X / this.rectangle.ActualWidth * this.gaugeControlX.Range);
            this.gaugeControlY.Value = gaugeControlY.Minimum + (mousePosition.Y / this.rectangle.ActualHeight * this.gaugeControlY.Range);
        }

        /// <summary>
        /// Handles the MouseLeave event of the rectangle control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
        private void rectangle_MouseLeave(object sender, MouseEventArgs e)
        {
            //this.gaugeControlX.Reset();
            //this.gaugeControlY.Reset();
        }

        /// <summary>
        /// Handles the Click event of the btnPointerFill control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnPointerFill_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.PointerFill = chooseColorBrush();
        }

        /// <summary>
        /// Handles the Click event of the btnPointerStroke control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnPointerStroke_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.PointerStroke = chooseColorBrush();
        }

        /// <summary>
        /// Handles the Click event of the btnScaleStroke control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnScaleStroke_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.ScaleStroke = chooseColorBrush();
        }

        /// <summary>
        /// Handles the Click event of the btnScaleValueForeground control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnScaleValueForeground_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.ScaleValueForeground = chooseColorBrush();
        }

        /// <summary>
        /// Handles the Click event of the btnValueDisplayForeground control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnValueDisplayForeground_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.ValueDisplayForeground = chooseColorBrush();
        }

        /// <summary>
        /// Handles the Click event of the btnMinorStampStroke control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnMinorStampStroke_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.MinorStampStroke = chooseColorBrush();
        }

        /// <summary>
        /// Handles the Click event of the btnMajorStampStroke control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void btnMajorStampStroke_Click(object sender, RoutedEventArgs e)
        {
            this.gaugeControlX.MajorStampStroke = chooseColorBrush();
        }

        /// <summary>
        /// Chooses the color brush.
        /// </summary>
        /// <returns>Selected Brush, when strno returns null</returns>
        private Brush chooseColorBrush()
        {
            if (this.ColorPicker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.Drawing.Color color = this.ColorPicker.Color;
                return new SolidColorBrush(Color.FromArgb(color.A, color.R, color.G, color.B));
            }
            return null;
        }

        #endregion Methods
    }
}
